package com.yjd.bi.borrow.dao.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.yjd.comm.base.dao.impl.BaseDaoImpl;
import com.yjd.comm.util.FrameUtil;
import com.yjd.bi.borrow.model.ArrearsFormModel;
import com.yjd.bi.borrow.dao.IArrearsFormDao;

/**
 * <b>description</b>：还款报表数据访问层 <br>
 * <b>time</b>：2016-06-30 15:13:29 <br>
 * <b>author</b>： chenpengfei@yijeidai.com
 */
@Component("arrearsFormDao")
public class ArrearsFormDaoImpl extends BaseDaoImpl implements IArrearsFormDao {

	private static final String SQLMAPNAMESPACE = ArrearsFormModel.class.getName();
	private static final String PKNAME = "id";

	@Override
	public String getPrimaryKeyName() {
		return PKNAME;
	}

	@Override
	public String getSqlmapNamespace() {
		return SQLMAPNAMESPACE;
	}
	
	/**
	 * 获取model列表
	 * 
	 * @param <T>
	 * @param paramMap
	 *            查询参数列表
	 * @return 返回结果列表
	 * @throws Exception
	 */
	@SuppressWarnings("rawtypes")
	public List getRecoveryByTime(Long stime, boolean write)
			throws Exception {
		List list = this.getSqlMap(write).queryForList(
				this.getStatement("getDailyBorrowCount"), FrameUtil.newHashMap("stime",stime));
		return list;
	}
	
	/**
	 * 获取符合条件的model的数量
	 * 
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	public long getBorrowerCount(Map<Object, Object> paramMap, boolean write)
			throws Exception {
		if (paramMap != null && paramMap.containsKey("rowstartindex")
				&& !paramMap.containsKey("dbtype")) {
			paramMap.put("dbtype", this.getDbtype());
		}
		return Long
				.parseLong(this.getSqlMap(write)
						.queryForObject(
								this.getStatement(
										"getBorrowerCount"),
								paramMap)
						.toString());
	}
	
	public double getFundsSum(Map<String, Object> paramMap, boolean b) {
		Object myObject = this.getSqlMap(b).queryForObject(this.getStatement("fieldSum"),paramMap);
		if (myObject != null) {
			return Double.parseDouble(myObject.toString());
		}
		return 0.00D;
	}
	
	public double fieldSelect(Map<String, Object> paramMap, boolean b) {
		Object myObject = this.getSqlMap(b).queryForObject(this.getStatement("fieldSelect"),paramMap);
		if (myObject != null) {
			return Double.parseDouble(myObject.toString());
		}
		return 0.00D;
	}

	public Double getRecoverPrice(Map<String, Object> paramMap, boolean b) {
		Object myObject = this.getSqlMap(b).queryForObject(this.getStatement("getRecoverPrice"),paramMap);
		if (myObject != null) {
			return Double.parseDouble(myObject.toString());
		}
		return 0.00D;
	}
	
	public Double getRemainSum(Map<String, Object> paramMap, boolean b) {
		Object myObject = this.getSqlMap(b).queryForObject(this.getStatement("getRemainSum"),paramMap);
		if (myObject != null) {
			return Double.parseDouble(myObject.toString());
		}
		return 0.00D;
	}
	
	public Double getSumPrice(Map<String, Object> paramMap, boolean b) {
		Object myObject = this.getSqlMap(b).queryForObject(this.getStatement("getSumPrice"),paramMap);
		if (myObject != null) {
			return Double.parseDouble(myObject.toString());
		}
		return 0.00D;
	}

	public Double getExpectPrice(Map<String, Object> paramMap, boolean b) {
		// TODO Auto-generated method stub
		Object myObject = this.getSqlMap(b).queryForObject(this.getStatement("getExpectPrice"),paramMap);
		if (myObject != null) {
			return Double.parseDouble(myObject.toString());
		}
		return 0.00D;
	}
}
